/**
 * 
 */
package br.com.consultsystems.negocio.impl.cadastro;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import br.com.consultsystems.dominio.cadastro.Imovel;
import br.com.consultsystems.negocio.spec.cadastro.ImovelNegocio;
import br.com.consultsystems.persistencia.spec.cadastro.ImovelPersistencia;

/**
 * @author Moralles
 *
 */
@Stateless(name = "imovelNegocio")
public class ImovelNegocioImpl implements ImovelNegocio {

	@EJB
	private ImovelPersistencia imovelPersistencia;

	@Override
	public Imovel merge(Imovel t) throws Exception {
		return imovelPersistencia.merge(t);
	}

	@Override
	public Imovel retrieve(Long id) throws Exception {
		return null;
	}

	@Override
	public List<Imovel> retrieveByIdCondominio(Long idCondominio) {
		return imovelPersistencia.retrieveByIdCondominio(idCondominio);
	}
	
	@Override
	public void remove(Imovel t) throws Exception {
		t = this.merge(t);
		imovelPersistencia.remove(t);
	}

	@Override
	public void refresh(Imovel t) throws Exception {
		imovelPersistencia.refresh(t);
	}

	@Override
	public List<Imovel> retrieveAll() throws Exception {
		return imovelPersistencia.retrieveAll();
	}

	@Override
	public List<Imovel> retrieveByFilter(String numero, String nomeCondominio) throws Exception {
		
		if(numero != null && !numero.isEmpty()) {
			return imovelPersistencia.retrieveByNumero(numero);			
		} else if(nomeCondominio != null && !nomeCondominio.isEmpty()) {
			return imovelPersistencia.retrieveByNomeCondominio(nomeCondominio);
		} else {
			 return new ArrayList<Imovel>();
		}

	}

}
